package com.firegod.live.vo;

import com.alibaba.fastjson.JSONObject;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.Objects;

@NoArgsConstructor
@Getter
public class LiveUser {

    public String name;
    public String userId;
    public String roomId;
    public Boolean owner;

    public LiveUser(String name, String userId, String roomId, Boolean owner) {
        this.name = name;
        this.userId = userId;
        this.roomId = roomId;
        this.owner = owner;
    }

    public LiveUser(String userId, String roomId) {
        this.userId = userId;
        this.roomId = roomId;
    }

    public JSONObject toJSONObject() {
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("userId", userId);
        jsonObject.put("roomId", roomId);
        jsonObject.put("name", name);
        jsonObject.put("owner", owner);
        return jsonObject;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        LiveUser liveUser = (LiveUser) o;
        return Objects.equals(userId, liveUser.userId) &&
                Objects.equals(roomId, liveUser.roomId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(userId, roomId);
    }
}
